package com.hb;

import cn.hutool.core.util.CharsetUtil;
import cn.hutool.crypto.Mode;
import cn.hutool.crypto.Padding;
import cn.hutool.crypto.symmetric.AES;
import cn.hutool.crypto.symmetric.SymmetricAlgorithm;
import cn.hutool.crypto.symmetric.SymmetricCrypto;

/**
 * Hello world!
 *
 */
public class App {
    public static void main( String[] args ) {
        System.out.println( "Hello World!" );

        String content = "1";
        String key = "qwer1234qwer1234";
        byte[] keyByte = key.getBytes();
        SymmetricCrypto aes = new SymmetricCrypto(SymmetricAlgorithm.AES, keyByte);
        String encryptStr = aes.encryptBase64(content);
        System.out.println("==========默认==============");
        System.out.println("加密结果：" + encryptStr);
        String decryptStr = aes.decryptStr(encryptStr, CharsetUtil.CHARSET_UTF_8);
        System.out.println("解密结果：" + decryptStr);
        System.out.println("==========AES/ECB/PKCS5Padding==============");
        AES aes1 = new AES(Mode.ECB, Padding.PKCS5Padding, keyByte);
        String encryptStr1 = aes1.encryptBase64(content);
        System.out.println("加密结果：" + encryptStr1);
        System.out.println("解密结果：" + aes1.decryptStr(encryptStr1, CharsetUtil.CHARSET_UTF_8));
    }
}
